<template>
    <h2>理财项目列表</h2>
    <FinanInfoContent v-slot="finan">
        <button @click="DeleteInfo(finan.id)" class="btn btn-danger">删除</button>
        <button @click="EditInfo(finan.id)" class="btn btn-primary">修改</button>

    </FinanInfoContent>
</template>

<script setup lang="ts">
import FinanInfoContent from './FinanInfoContent.vue'
import axios from 'axios';
import { useRouter } from 'vue-router'

const router = useRouter();

//const Code=ref()
//删除
const DeleteInfo = (I_Id: any) => {
    if (confirm("确定要删除吗？")) {
        axios.delete("https://localhost:44387/api/Finans/Delete", {
            params: {
                F_id: I_Id
            }
        })
            .then(res => {
                //处理响应数据
                console.log(res.data);
                if (res.data > 0) {
                    alert("理财信息删除成功");
                }
                else if (res.data == -1) {
                    alert("理财人数大于0 不能删除")
                }
                else {
                    alert("理财信息删除失败");
                }

                //刷新页面
                window.location.reload();
            })
            .catch(error => {
                //处理错误
                console.log(error);
            })
    }
}
//通过路由跳转到修改页面
const EditInfo = (I_Id: any) => {
    router.push({
        path: '/EditFinanInfo',
        query: {
            F_id: I_Id
        }
    })
}


</script>
